


# to manipulate data
library(tidyverse)

# to estimate IV regressions
library(AER)
library(ivpack)

# to generate results tables
library(stargazer)



# load data
load("full_data_iv.RData")



# INSTRUMENT #1 (Stubbs et al 2020)
# instrument for participation: proportion of years under an agreement times log of IMF liquidity ratio 
# instrument for conditionality: country-specific average of conditions times log of the IMF liquidity ratio
iv_df <- iv_df %>%
  group_by(iso3c) %>%
  mutate(proportion_years_imf_program = sum(imf_program)/41,
         average_conditions = mean(resource_conditionality)) %>%
  ungroup() %>%
  mutate(imf_liquidity_ratio_log = log(imf_liquidity_ratio),
         liquidity_ratio_instrument_participation = proportion_years_imf_program*imf_liquidity_ratio_log,
         liquidity_ratio_instrument_condition = average_conditions*imf_liquidity_ratio_log)
summary(iv_df$liquidity_ratio_instrument_participation)
summary(iv_df$liquidity_ratio_instrument_condition)

# INSTRUMENT #2 (Chapman et al 2017)
# instrument for participation: none
# isntrument for conditionality: number of countries under agreement in a given year 
iv_df <- iv_df %>%
  group_by(year) %>%
  mutate(number_participating_countries = sum(imf_program)) %>%
  ungroup()
summary(iv_df$number_participating_countries)


# INSTRUMENT #3 (Beazer and Woo 2016)
# instrument for participation: none
# instrument for conditionality: total loan disbursement in a given year, in billions of dollars
summary(iv_df$disbursement)


# INSTRUMENT #4 (Dreher et al 2009)
# instrument for participation: UNSC temporary membership
# instrument for conditionality: none
iv_df <- iv_df %>%
  mutate(unsc = as.factor(unsc))
summary(iv_df$unsc)


# INSTRUMENT #5 (Casper 2017)
# instrument for participation: share of a country’s nationals who work at the IMF 
# instrument for conditionality: none
summary(iv_df$imf_staff_percent)



# some diagnostics:
# correlation between oil prices and instrument #1
testing_correlation <- iv_df %>%
  select(oil_price,imf_liquidity_ratio) %>%
  unique()
cor.test(testing_correlation$oil_price, testing_correlation$imf_liquidity_ratio, method=c("pearson", "kendall", "spearman"))


# correlation between oil prices and instrument #2
testing_correlation <- iv_df %>%
  select(oil_price,number_participating_countries) %>%
  unique()
cor.test(testing_correlation$oil_price, testing_correlation$number_participating_countries, method=c("pearson", "kendall", "spearman"))




######### instrumental variables
# short term

# INSTRUMENT #1  
ivreg1 <- ivreg(short_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  liquidity_ratio_instrument_participation + liquidity_ratio_instrument_condition +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg1_r <- ivreg1 %>% 
  coeftest(vcovHC(ivreg1, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #2
ivreg2 <- ivreg(short_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_program + number_participating_countries +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg2_r <- ivreg2 %>% 
  coeftest(vcovHC(ivreg2, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #3
ivreg3 <- ivreg(short_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_program + disbursement + 
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg3_r <- ivreg3 %>% 
  coeftest(vcovHC(ivreg3, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #4
ivreg4 <- ivreg(short_term ~ imf_program + resource_conditionality + 
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  unsc + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg4_r <- ivreg4 %>% 
  coeftest(vcovHC(ivreg4, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #5
ivreg5 <- ivreg(short_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_staff_percent + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg5_r <- ivreg5 %>% 
  coeftest(vcovHC(ivreg5, type = 'HC0', cluster = c('iso3c', 'Summary')))


summary(ivreg4, diagnostics = T)

# TABLE E.2 (with clustered standard errors)
stargazer(ivreg1_r,ivreg2_r,ivreg3_r,ivreg4_r,ivreg5_r, omit="iso3c", #type="text",
          column.labels = c("IV: liquidity x share yrs under agreement",
                            "IV: # countries under agreement",
                            "IV: total disbursement",
                            "IV: UNSC temporary membership",
                            "IV: % of US staff"),
          covariate.labels = c("Program Participation = 1",
                               "Resource Conditionality (%)",
                               "Previous Short-Term Policy",
                               "Previous Long-Term Policy",
                               "GDP per Capita (Log)",
                               "GDP Growth (%)",
                               "Resource Rents (% GDP)",
                               "Working Age Population (%)",
                               "Field Discovery = 1",
                               "Oil Price (USD)",
                               "Crisis = 1",
                               "WB Extractive Project",
                               "Democracy (Polity2)",
                               "Left Executive = 1",
                               "Election Year = 1",
                               "Oil Company Nationalization = 1",
                               "War = 1",
                               "EITI Member = 1"),
          no.space = T,
          dep.var.labels = "Short-Term Policy (Models 1--6)",
          omit.stat = c("rsq","adj.rsq","ser"),
          add.lines = list(c("F Statistic for IV 1","1.515","--","--","3.098*","0.334"),
                           c("F Statistic for IV 2","15.707***","1.162","0.022","--","--"),
                           c("Wu-Hausman Test","1.890","0.189","0.682","1.534","0.004")))

# retrieve n etc
stargazer(ivreg1,ivreg2,ivreg3,ivreg4,ivreg5, omit="iso3c", #type="text",
          column.labels = c("IV: liquidity x share yrs under agreement",
                            "IV: # countries under agreement",
                            "IV: total disbursement",
                            "IV: UNSC temporary membership",
                            "IV: % of US staff"),
          covariate.labels = c("Program Participation = 1",
                               "Resource Conditionality (%)",
                               "Previous Short-Term Policy",
                               "Previous Long-Term Policy",
                               "GDP per Capita (Log)",
                               "GDP Growth (%)",
                               "Resource Rents (% GDP)",
                               "Working Age Population (%)",
                               "Field Discovery = 1",
                               "Oil Price (USD)",
                               "Crisis = 1",
                               "WB Extractive Project",
                               "Democracy (Polity2)",
                               "Left Executive = 1",
                               "Election Year = 1",
                               "Oil Company Nationalization = 1",
                               "War = 1",
                               "EITI Member = 1"),
          no.space = T,
          dep.var.labels = "Short-Term Policy (Models 1--6)",
          omit.stat = c("rsq","adj.rsq","ser"),
          add.lines = list(c("F Statistic for IV 1","1.515","--","--","3.098*","0.334"),
                           c("F Statistic for IV 2","15.707***","1.162","0.022","--","--"),
                           c("Wu-Hausman Test","1.890","0.189","0.682","1.534","0.004")))


# long term
# INSTRUMENT #1  
ivreg6 <- ivreg(long_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  liquidity_ratio_instrument_participation + liquidity_ratio_instrument_condition +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg6_r <- ivreg6 %>% 
  coeftest(vcovHC(ivreg1, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #2
ivreg7 <- ivreg(long_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_program + number_participating_countries +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg7_r <- ivreg7 %>% 
  coeftest(vcovHC(ivreg7, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #3
ivreg8 <- ivreg(long_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_program + disbursement + 
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg8_r <- ivreg8 %>% 
  coeftest(vcovHC(ivreg8, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #4
ivreg9 <- ivreg(long_term ~ imf_program + resource_conditionality + 
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  unsc + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg9_r <- ivreg9 %>% 
  coeftest(vcovHC(ivreg9, type = 'HC0', cluster = c('iso3c', 'Summary')))


# INSTRUMENT #5
ivreg10 <- ivreg(long_term ~ imf_program + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3) |
                  imf_staff_percent + resource_conditionality +
                  previous_short_term + previous_long_term + 
                  log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                  working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                  polity2_lag + left_executive_lag + 
                  election_lag + nationalization_oc_lag + 
                  any_war_lag + 
                  eiti_member_lag + as.factor(iso3c) + poly(t,3), data = iv_df)

ivreg10_r <- ivreg10 %>% 
  coeftest(vcovHC(ivreg10, type = 'HC0', cluster = c('iso3c', 'Summary')))


summary(ivreg6, diagnostics = T)

# TABLE E.2 (with clustered standard errors)
stargazer(ivreg6_r,ivreg7_r,ivreg8_r,ivreg9_r,ivreg10_r, omit="iso3c", #type="text",
          column.labels = c("IV: liquidity x share yrs under agreement",
                            "IV: # countries under agreement",
                            "IV: total disbursement",
                            "IV: UNSC temporary membership",
                            "IV: % of US staff"),
          covariate.labels = c("Program Participation = 1",
                               "Resource Conditionality (%)",
                               "Previous Short-Term Policy",
                               "Previous Long-Term Policy",
                               "GDP per Capita (Log)",
                               "GDP Growth (%)",
                               "Resource Rents (% GDP)",
                               "Working Age Population (%)",
                               "Field Discovery = 1",
                               "Oil Price (USD)",
                               "Crisis = 1",
                               "WB Extractive Project",
                               "Democracy (Polity2)",
                               "Left Executive = 1",
                               "Election Year = 1",
                               "Oil Company Nationalization = 1",
                               "War = 1",
                               "EITI Member = 1"),
          no.space = T,
          dep.var.labels = "Long-Term Policy (Models 1--6)",
          omit.stat = c("rsq","adj.rsq","ser"),
          add.lines = list(c("F Statistic for IV 1","1.515","--","--","3.098*","0.334"),
                           c("F Statistic for IV 2","15.707***","1.162","0.022","--","--"),
                           c("Wu-Hausman Test","2.054","2.220","0.412","4.406","0.014")))


# retrieve n etc
stargazer(ivreg6,ivreg7,ivreg8,ivreg9,ivreg10, omit="iso3c", #type="text",
          column.labels = c("IV: liquidity x share yrs under agreement",
                            "IV: # countries under agreement",
                            "IV: total disbursement",
                            "IV: UNSC temporary membership",
                            "IV: % of US staff"),
          covariate.labels = c("Program Participation = 1",
                               "Resource Conditionality (%)",
                               "Previous Short-Term Policy",
                               "Previous Long-Term Policy",
                               "GDP per Capita (Log)",
                               "GDP Growth (%)",
                               "Resource Rents (% GDP)",
                               "Working Age Population (%)",
                               "Field Discovery = 1",
                               "Oil Price (USD)",
                               "Crisis = 1",
                               "WB Extractive Project",
                               "Democracy (Polity2)",
                               "Left Executive = 1",
                               "Election Year = 1",
                               "Oil Company Nationalization = 1",
                               "War = 1",
                               "EITI Member = 1"),
          no.space = T,
          dep.var.labels = "Long-Term Policy (Models 1--6)",
          omit.stat = c("rsq","adj.rsq","ser"),
          add.lines = list(c("F Statistic for IV 1","1.515","--","--","3.098*","0.334"),
                           c("F Statistic for IV 2","15.707***","1.162","0.022","--","--"),
                           c("Wu-Hausman Test","2.054","2.220","0.412","4.406","0.014")))









# FIRST STAGES
# INSTRUMENT #1
first_stage1a <- lm(imf_program ~ liquidity_ratio_instrument_participation +
                 previous_short_term + previous_long_term + 
                 log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                 working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                 polity2_lag + left_executive_lag + 
                 election_lag + nationalization_oc_lag + 
                 any_war_lag + 
                 eiti_member_lag +
                 as.factor(iso3c) + 
                 poly(t,3), data = iv_df)

first_stage1a_r <- first_stage1a %>% 
  coeftest(vcovHC(first_stage1a, type = 'HC0', cluster = c('iso3c', 'Summary')))

first_stage1b <- lm(resource_conditionality ~ liquidity_ratio_instrument_condition +
                      previous_short_term + previous_long_term + 
                      log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                      working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                      polity2_lag + left_executive_lag + 
                      election_lag + nationalization_oc_lag + 
                      any_war_lag + 
                      eiti_member_lag +
                      as.factor(iso3c) + 
                      poly(t,3), data = iv_df)

first_stage1b_r <- first_stage1b %>% 
  coeftest(vcovHC(first_stage1b, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #2
first_stage2 <- lm(resource_conditionality ~ imf_program + number_participating_countries + 
               previous_short_term + previous_long_term + 
               log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
               working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
               polity2_lag + left_executive_lag + 
               election_lag + nationalization_oc_lag + 
               any_war_lag + 
               eiti_member_lag +
               as.factor(iso3c) + 
               poly(t,3), data = iv_df)

first_stage2_r <- first_stage2 %>% 
  coeftest(vcovHC(first_stage2, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #3
first_stage3 <- lm(resource_conditionality ~ imf_program + disbursement + 
               previous_short_term + previous_long_term + 
               log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
               working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
               polity2_lag + left_executive_lag + 
               election_lag + nationalization_oc_lag + 
               any_war_lag + 
               eiti_member_lag +
               as.factor(iso3c) + 
               poly(t,3), data = iv_df)

first_stage3_r <- first_stage3 %>% 
  coeftest(vcovHC(first_stage3, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #4
first_stage4 <- lm(imf_program ~ unsc + resource_conditionality +
               previous_short_term + previous_long_term + 
               log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
               working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
               polity2_lag + left_executive_lag + 
               election_lag + nationalization_oc_lag + 
               any_war_lag + 
               eiti_member_lag +
               as.factor(iso3c) + 
               poly(t,3), data = iv_df)

first_stage4_r <- first_stage4 %>% 
  coeftest(vcovHC(first_stage4, type = 'HC0', cluster = c('iso3c', 'Summary')))

# INSTRUMENT #5
first_stage5 <- lm(imf_program ~ imf_staff_percent + resource_conditionality +
                previous_short_term + previous_long_term + 
                log_gdp_pc_constant_lag + gdp_growth_lag + resource_rents_lag + 
                working_age_pop_lag + field_discovery_lag + oil_price_lag + crisis_lag + wb_extractive_project_lag +
                polity2_lag + left_executive_lag + 
                election_lag + nationalization_oc_lag + 
                any_war_lag + 
                eiti_member_lag +
                as.factor(iso3c) + 
                poly(t,3), data = iv_df)

first_stage5_r <- first_stage5 %>% 
  coeftest(vcovHC(first_stage5, type = 'HC0', cluster = c('iso3c', 'Summary')))

#first table: participation instruments
stargazer(first_stage1a_r,
          first_stage4_r,first_stage5_r,
          omit="iso3c", type="text")

#second table: conditionality instruments
stargazer(first_stage1b_r,
          first_stage2_r,first_stage3_r,
          omit="iso3c", type="text")

# TABLE E.3: combine
stargazer(first_stage1b_r,
          first_stage2_r,first_stage3_r,
          omit="iso3c", #type="text",
          covariate.labels = c("IV 2: conditionality instrument 1",
                               #"IV 1: participation instrument 1",
                               "Program Participation = 1",
                               "IV 2: conditionality instrument 2",
                               "IV 2: conditionality instrument 3",
                               #"IV 1: participation instrument 2",
                               #"IV 1: participation instrument 3",
                               #"Resource Conditionality (%)",
                               "Previous Short-Term Policy",
                               "Previous Long-Term Policy",
                               "GDP per Capita (Log)",
                               "GDP Growth (%)",
                               "Resource Rents (% GDP)",
                               "Working Age Population (%)",
                               "Field Discovery = 1",
                               "Oil Price (USD)",
                               "Crisis = 1",
                               "WB Extractive Project",
                               "Democracy (Polity2)",
                               "Left Executive = 1",
                               "Election Year = 1",
                               "Oil Company Nationalization = 1",
                               "War = 1",
                               "EITI Member = 1"),
          dep.var.labels = c("Resource Conditionality (%)"),
          no.space = T)
